#ifndef XML_CONFIG_H
#define XML_CONFIG_H

#include <xercesc/dom/DOM.hpp>
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMDocumentType.hpp>
#include <xercesc/dom/DOMElement.hpp>
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMImplementationLS.hpp>
#include <xercesc/dom/DOMNodeIterator.hpp>
#include <xercesc/dom/DOMNodeList.hpp>
#include <xercesc/dom/DOMText.hpp>

#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/util/XMLUni.hpp>

#include <string>
#include <stdexcept>

using namespace xercesc;
using namespace std;

typedef struct ICEServer_struct {
	string protoPort;
	string recvPort;
	string transPort;
	string timeout;
}ICEServerConfig;

typedef struct RecvService_struct {
	string dynamicLib;
	string directory;
	string recvProtoPort;
}RecvServiceConfig;

typedef struct TransService_struct {
	string dynamicLib;
	string directory;
	string transProtoPort;
}TransServiceConfig;

typedef struct Database_struct {
	string dbName;
	string dbServer;
	string dbUser;
	string dbPasswd;
}DatabaseConfig;

class xmlConfig
{
private:
	ICEServerConfig m_server;
	//ServiceConfig m_service;
	DatabaseConfig m_database;

	//Internal use only
	xercesc::XercesDOMParser *parser;
	DOMDocument *xmlDoc;
	DOMElement *elementRoot;

	XMLCh* TAG_AccountSystem;
	XMLCh* TAG_IceServer;
	XMLCh* TAG_Service;
	XMLCh* TAG_Database;

public:
	xmlConfig();
	~xmlConfig();

	int readXmlConfig(std::string &configFile) throw(std::runtime_error);

	int getICEServerConfig(ICEServerConfig &iceServerConfig);
	int getRecvServiceConfig(RecvServiceConfig &recvServiceConfig);
	int getTransServiceConfig(TransServiceConfig &transServiceConfig);
	int getDatabaseConfig(DatabaseConfig &databaseConfig);

	//saveConfigFile();
	//saveBakConfigFile();

private:
	int getElementText(const DOMElement *pNode, string &text);
	DOMElement* getElementNode(const DOMElement *pNode, string nodeName);
	//getICE();
	//getService();

	string getDBName();
	string getDBServer();
	string getDBUser();
	string getDBPasswd();

	string getICEProtoPort();
	string getICERecvPort();
	string getICETransPort();
	string getICETimeout();

	string getRecvDynamicLib();
	string getRecvDirectory();
	string getRecvProtoPort();
	
	string getTransDynamicLib();
	string getTransDirectory();
	string getTransProtoPort();
};

#endif 
